#! /bin/bash
res=0
read -p "请输入本机root用户正确的密码:  " PASSWD

# install rpm
yum install -y expect 1>/dev/null

/usr/bin/expect <<EOF
set timeout 10
spawn ssh -o Ciphers=sm4-ctr -o Macs=hmac-sm3 -o KexAlgorithms=sm2-sm3 -o Hostkeyalgorithms=sm2 root@localhost
expect {
    "yes/no" { send "yes\n";exp_continue }
    "password" { send "${PASSWD}\n" }
  }
expect "password" { send "{$PASSWD}\n" }
interact
EOF

[ "$?" = "0" ] || res=1

# 判断用例执行是否成功
[ "$res" = "0" ] && echo -e "\033[32m-----------------test PASSED----------------\033[0m" || echo -e "\033[31m-----------------test FAILD----------------\033[0m"